# 构建方法
# docker build --build-arg user=${USER} --build-arg password="shuchengm3" -t ubuntu20_string:latest -f build_for_user.dockerfile .

# 基础镜像
FROM ubuntu:jammy

# 添加参数
ARG user
ARG password

# 添加标签
LABEL maintainer="zhaoshucheng"
LABEL email="bmwshucheng@126.com"

# 换源，换源的思路是最好 copy ubuntu 官方的
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted" > /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ jammy universe" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ jammy-updates universe" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ jammy multiverse" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ jammy-updates multiverse" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ jammy-security universe" >> /etc/apt/sources.list
RUN echo "deb http://mirrors.aliyun.com/ubuntu/ jammy-security multiverse" >> /etc/apt/sources.list


# 安装软件
RUN apt-get update && apt-get upgrade
RUN apt-get install \
    -y \
    python3 \
    pip \
    sudo \
    python3.10-venv
RUN pip3 install \
    -i https://pypi.tuna.tsinghua.edu.cn/simple \
    torch \
    torchvision \
    torchaudio

# 添加用户
RUN chmod 640 /etc/shadow
RUN useradd --create-home --no-log-init --shell /bin/bash ${user} \
    && adduser ${user} sudo \
    && echo "${user}:${password}" | chpasswd
WORKDIR /home/${user}
USER ${user}